package com.yf.construction.risk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.BaseIdReqDTO;
import com.yf.base.api.api.dto.BaseIdsReqDTO;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.construction.risk.dto.ConstructionRiskDTO;
import com.yf.construction.risk.service.ConstructionRiskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 控制器
 * </p>
 *
 * @author anyone
 * @since 2024-09-13 16:38
 */
@Api(tags = {""})
@RestController
@RequestMapping("/api/construction/risk")
public class ConstructionRiskController extends BaseController {

    @Autowired
    private ConstructionRiskService baseService;

    /**
     * 添加或修改
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody ConstructionRiskDTO reqDTO) {
        baseService.save(reqDTO);
        return super.success();
    }

    /**
     * 批量删除
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "批量删除")
    @PostMapping("/delete")
    public ApiRest delete(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        baseService.delete(reqDTO.getIds());
        return super.success();
    }

    /**
     * 查找详情
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "查找详情")
    @PostMapping("/detail")
    public ApiRest<ConstructionRiskDTO> detail(@RequestBody BaseIdReqDTO reqDTO) {
        ConstructionRiskDTO dto = baseService.detail(reqDTO.getId());
        return super.success(dto);
    }

    /**
     * 分页查找
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<ConstructionRiskDTO>> paging(@RequestBody PagingReqDTO<ConstructionRiskDTO> reqDTO) {

        //分页查询并转换
        IPage<ConstructionRiskDTO> page = baseService.paging(reqDTO);

        return super.success(page);
    }

    /**
     * 查找列表，每次最多返回200条数据
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "查找列表")
    @PostMapping("/list")
    public ApiRest<List<ConstructionRiskDTO>> list(@RequestBody ConstructionRiskDTO reqDTO) {
        // 查找列表
        List<ConstructionRiskDTO> dtoList = baseService.list(reqDTO);
        return super.success(dtoList);
    }
}
